<template>
<!-- 初审录入 -->
    <div>
      <el-container>
         <el-header style="padding: 0px;display:flex;justify-content:space-between;align-items: center">
          <div style="display: inline">
            <el-input
            placeholder="请输入合同编号"
            clearable
            style="width: 300px;margin: 0px;padding: 0px;"
            size="mini"
            :disabled="advanceSearchViewVisible"
            @keyup.enter.native="searchEmp"
            prefix-icon="el-icon-search"
            v-model="contractNo">
            </el-input>
            <el-button type="primary" size="mini" style="margin-left: 5px"
              icon="el-icon-search" @click="searchEmp" :disabled="advanceSearchViewVisible">搜索
            </el-button>
            <el-button slot="reference" type="primary" size="mini" style="margin-left: 5px"
              @click="showAdvanceSearchView">
              <i class="fa fa-lg" v-bind:class="[advanceSearchViewVisible ? faangledoubleup:faangledoubledown]"
                style="margin-right: 5px"></i>高级搜索
            </el-button>
          </div>
          <div style="margin-left: 5px;margin-right: 20px;display: inline">
          
            <el-button type="success" size="mini" @click="exportEmps" :disabled="exportLoading" :loading="exportLoading">
              <i class="fa fa-lg fa-level-down" style="margin-right: 5px"></i>导出清单
            </el-button>
            <el-button type="primary" size="mini" icon="el-icon-plus"
                     @click="addContract">
            录入合同
            </el-button>
          </div>
         </el-header>
        <el-main>
          <!-- 高级搜索 -->
          <div>
            <transition name="slide-fade">
              <div v-show="advanceSearchViewVisible" class="senior"> 
                  <el-row>
                    <el-col :span="8">
                        <span>服务人员:</span>
                        <el-select
                          v-model="form.salemanName"
                          filterable
                          remote
                          placeholder="请输入服务人员"
                          :remote-method="inputsalemanNameMethod"
                          :loading="inputsalemanNameLoading"
                          @change="salemanNameChange" clearable>
                          <el-option
                            v-for="item in inputsalemanNameArray"
                            :key="item.salemanId"
                            :label="item.area+item.part+item.group+item.salemanName"
                            :value="item.salemanName"
                          >
                          </el-option>
                        </el-select>
                    </el-col>
                    <el-col :span="8">
                      <span>客户姓名:</span>
                      <el-input
                        placeholder="请输入客户姓名"
                        v-model="customerName"
                        clearable>
                      </el-input>
                    </el-col>
                    <el-col :span="8">
                      <span>身份证号:</span>
                      <el-input
                        placeholder="请输入身份证号"
                        v-model="idcard"
                        clearable>
                      </el-input>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <span>录入时间段:</span>  
                      <el-date-picker
                        v-model="time1"
                        type="daterange"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        value-format="yyyy-MM-dd"
                        :picker-options="birthdayOptions">
                      </el-date-picker>
                    </el-col>
                    <el-col :span="12">
                      <span>回销时间段:</span>  
                      <el-date-picker
                        v-model="time2"
                        type="daterange"
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        value-format="yyyy-MM-dd"
                        :picker-options="birthdayOptions">
                      </el-date-picker>
                    </el-col>
                    <el-col :span="8">
                      <span>部门：</span>
                      <el-select v-model="department" placeholder="请选择部门" clearable>
                        <el-option
                          v-for="item in departmentArr"
                          :key="item"
                          :label="item"
                          :value="item">
                        </el-option>
                      </el-select>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="8">
                      <el-button icon="el-icon-search" type="primary" size="mini" @click="search">搜索</el-button>
                      <el-button size="mini" @click="cancelSearch">取消</el-button>
                    </el-col>
                  </el-row>  
              </div>  
            </transition>
          </div>
          
          <!-- 表单列表 -->
          <div>
            <el-table
              :data="table"
              v-loading="tableLoading"
              border
              stripe 
              size="mini"
              height="500"
              style="width: 100%">
              <el-table-column
                label="合同编号"
                prop="contractNo"
                align="center"
                fixed
                width="120">
              </el-table-column>
              <el-table-column
                width="180"
                align="center"
                fixed
                label="产品名称"
                prop="productName">
              </el-table-column>
              <el-table-column
                width="100"
                align="center"
                fixed
                label="资产受让人"
                prop="customerName">
              </el-table-column>
              <el-table-column
                align="center"
                prop="createdTime"
                label="录入时间"
                width="150">
              </el-table-column>
              
              <el-table-column
                width="85"
                align="center"
                label="录入人"
                prop="createdBy">
              </el-table-column>
              
              <el-table-column
                width="150"
                align="center"
                label="身份证号"
                prop="idCard">
              </el-table-column>
              <el-table-column
                width="100"
                label="生日"
                align="center"
                prop="birthday">
              </el-table-column>
              <el-table-column
                label="年龄"
                align="center"
                prop="age">
              </el-table-column>
              <el-table-column
                label="性别"
                prop="sex"
                align="center">
              </el-table-column>
              <el-table-column
                width="180"
                align="center"
                label="打款账号"
                prop="payBankCard">
              </el-table-column>
              <el-table-column
                width="180"
                align="center"
                label="收款账号"
                prop="receiveBankCard">
              </el-table-column>
              <el-table-column
                width="220"
                align="center"
                label="打款银行开户行"
                prop="payOpeningBank">
              </el-table-column>
              <el-table-column
                align="center"
                width="220"
                label="收款银行开户行"
                prop="receiveOpeningBank">
              </el-table-column>
              <el-table-column
                width="100"
                align="center"
                label="联系电话"
                prop="telPhone">
              </el-table-column>
              <el-table-column
                width="300"
                align="center"
                label="联系地址"
                prop="address">
              </el-table-column>
              <el-table-column
                align="center"
                label="付款方式"
                prop="investmentType">
              </el-table-column>
              <el-table-column
                width="100"
                align="center"
                label="资产转让总额"
                prop="totalAssets">
              </el-table-column>
              <el-table-column
                align="center"
                width="100"
                label="银行打款日期"
                prop="payDate">
              </el-table-column>
              <el-table-column
                width="85"
                align="center"
                label="预期收益率(%)"
                prop="returnRate">
              </el-table-column>
              <el-table-column
                width="150"
                align="center"
                label="标准业务折标系数"
                prop="standardCoefficient">
              </el-table-column>
              <el-table-column
                width="95"
                align="center"
                label="服务人员"
                prop="salemanInfo.salemanName">
              </el-table-column>
              <el-table-column
                width="95"
                align="center"
                label="区"
                prop="salemanInfo.area">
              </el-table-column>
              <el-table-column
                width="95"
                align="center"
                label="部"
                prop="salemanInfo.part">
              </el-table-column>
              <el-table-column
                width="95"
                align="center"
                label="组"
                prop="salemanInfo.group">
              </el-table-column>
              <el-table-column
                align="center"
                width="70"
                label="新老客户"
                prop="customerType">
              </el-table-column>
              <el-table-column
                align="center"
                width="150"
                label="回执回销时间"
                prop="receiptSellBackTime">
              </el-table-column>
              <el-table-column
                align="center"
                width="150"
                label="驳回时间"
                prop="rejectionTime"
                >
              </el-table-column>
              <el-table-column
                width="200"
                align="center"
                label="驳回理由"
                prop="remark"
                :show-overflow-tooltip="true">
              </el-table-column>
              <el-table-column
                align="center"
                width="120"
                label="状态"
                fixed="right"
                prop="status">
              </el-table-column>
              <el-table-column
                fixed="right"
                align="left"
                label="操作"
                width="250">
                <template slot-scope="scope">
                  <el-button style="padding: 3px 4px 3px 4px;margin: 2px" type="primary"
                            size="mini" @click="showEditEmpView(scope.row)" v-if="scope.row.status!='财务驳回'">查看信息
                  </el-button>
                  <el-button style="padding: 3px 4px 3px 4px;margin: 2px" type="danger"
                            size="mini" @click="editEditEmpView(scope.row)" v-if="scope.row.status=='财务驳回'">修改信息
                  </el-button>
                  <el-button type="success" style="padding: 3px 4px 3px 4px;margin: 2px" size="mini"
                    @click="TimeEmp(scope.row)">填写回执回销时间
                  </el-button>
                </template>
              </el-table-column>
            </el-table>
            <el-pagination
                background
                :page-size="pageSize"
                :current-page="currentPage"
                @current-change="currentChange"
                layout="prev, pager, next"
                :total="totalCount"
                style="margin:50px;">
            </el-pagination>
            <div style="margin:30px 0;" class="fw">共{{Math.ceil(totalCount/pageSize)}}页,{{totalCount}}条信息</div>
          </div>
        </el-main>
        <!-- 录入合同 -->
        <div id="inputContract">
          <template>
            <el-dialog :title="form.title" :visible.sync="dialogFormVisible" 
              v-loading="dialogLoading"
              :close-on-click-modal="false"
              @close="dialogClose" width="1200px"
              >
              <el-form :model="form" :rules="rules" ref="form">
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="合同编号:"  prop='contractNo'>
                      <el-select
                        v-model="form.contractNo"
                        filterable
                        remote
                        placeholder="请输入合同编号"
                        :remote-method="inputContractNoMethod"
                        :loading="inputContractNoLoading"
                        @change="contractNoChange" clearable
                        :disabled="form.disabled">
                          <el-option
                            v-for="item in inputContractNoArray"
                            :key="item.contractNo"
                            :label="item.contractNo"
                            :value="item.contractNo"
                          >
                          </el-option>
                        </el-select>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="产品名称:" >
                      {{form.productName}}
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="折标系数:" >
                      {{form.standardCoefficient}}
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="资产受让人:" prop='customerName'>
                      <el-autocomplete
                        v-model="form.customerName"
                        :fetch-suggestions="querySearchAsync"
                        placeholder="请输入资产受让人"
                        @select="selectName" clearable
                        :disabled="form.disabled"
                        style="width:45%;"
                      >
                      <template slot-scope="{ item }">
                        <div class="name">{{ item.value }}</div>
                        <div class="idcard">{{ item.idCard }}</div>
                      </template>
                      </el-autocomplete>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="身份证号:"  prop='idCard'>
                      <el-input type="text" auto-complete="off" placeholder="请输入身份证号" v-model="form.idCard" 
                      clearable :disabled="form.disabled" @change="idCardChange">
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="性别:"  prop='sex'>
                        <el-radio v-model="form.sex" label="男"  :disabled="form.disabled">男</el-radio>
                        <el-radio v-model="form.sex" label="女"  :disabled="form.disabled">女</el-radio>  
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="付款方式:" prop="investmentType">
                      <el-select v-model="form.investmentType" placeholder="请选择" clearable :disabled="form.disabled">
                        <el-option
                          v-for="item in form.investmentTypeArray"
                          :key="item.value"
                          :label="item.label"
                          :value="item.value">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </el-col> 
                  <el-col :span="8">
                    <el-form-item label="生日:"  prop='birthday'>
                      <el-date-picker
                        v-model="form.birthday"
                        type="date"
                        placeholder="选择日期"
                        value-format="yyyy-MM-dd"
                        :disabled="form.disabled"
                        :picker-options="birthdayOptions">
                      </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="年龄:"  prop='age'>
                      <el-input type="text" auto-complete="off" placeholder="请输入年龄" v-model="form.age" 
                      :disabled="form.disabled" clearable>
                      </el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="打款账号:"  prop='payBankCard'>
                      <el-input type="text" auto-complete="off" placeholder="请输入打款账号" v-model="form.payBankCard" 
                      :disabled="form.disabled" clearable>
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8">
                    <el-form-item label="收款账号:"  prop='receiveBankCard'>
                      <el-input type="text" auto-complete="off" placeholder="请输入收款账号" v-model="form.receiveBankCard" 
                      :disabled="form.disabled" clearable>
                      </el-input>
                    </el-form-item>
                  </el-col>
                  
                  <el-col :span="8">
                    <el-form-item label="服务人员:" prop="salemanName">
                      <el-select
                        v-model="form.salemanName"
                        filterable
                        remote
                        placeholder="请输入服务人员"
                        :remote-method="inputsalemanNameMethod"
                        :loading="inputsalemanNameLoading"
                        @change="salemanNameChange" clearable :disabled="form.disabled">
                          <el-option
                            v-for="item in inputsalemanNameArray"
                            :key="item.salemanId"
                            :label="item.area+item.part+item.group+item.salemanName"
                            :value="item.salemanName"
                          >
                          </el-option>
                        </el-select>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="12" class="longinput">
                    <el-form-item label="联系电话:"  prop='telPhone'>
                      <el-input type="text" auto-complete="off" placeholder="请输入联系电话" v-model="form.telPhone" 
                      :disabled="form.phoneDisable" clearable>
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12" class="longinput">
                    <el-form-item label="联系地址:"  prop='address'>
                      <el-input type="text" auto-complete="off" placeholder="请输入联系地址" v-model="form.address" 
                      :disabled="form.disabled" clearable>
                      </el-input>
                    </el-form-item>
                  </el-col>  
                </el-row>
                <el-row>
                  <el-col :span="12" class="longinput">
                    <el-form-item label="打款银行开户行:"  prop='payOpeningBank'>
                      <el-input type="text" auto-complete="off" placeholder="请输入打款银行开户行" v-model="form.payOpeningBank" 
                      :disabled="form.disabled" clearable>
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="12" class="longinput">
                    <el-form-item label="收款银行开户行:"  prop='receiveOpeningBank'>
                      <el-input type="text" auto-complete="off" placeholder="请输入收款银行开户行" v-model="form.receiveOpeningBank" 
                      :disabled="form.disabled" clearable>
                      </el-input>
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>   
                  <el-col :span="12" class="longinput">
                    <el-form-item label="资产转让总额:"  prop='totalAssets'>
                      <el-input type="text" auto-complete="off" v-model="form.totalAssets" placeholder="请输入资产转让总额" 
                      class="input-with-select" 
                      :disabled="form.disabled" clearable> 
                      <el-button slot="append" icon="el-icon-search" @click="countProfit" 
                      :loading="form.countLoading" :disabled="form.disabled">计算收益率</el-button>
                      </el-input>
                    </el-form-item>
                  </el-col>
                  <el-col :span="4">
                    <el-form-item label="预期收益率:">
                      {{form.totalAssetsReturn}}
                    </el-form-item>
                  </el-col>
                </el-row>
                <el-row>
                  <el-col :span="8">
                    <el-form-item label="银行打款日期:" prop='payDate'>
                        <el-date-picker
                            v-model="form.payDate"
                            type="date"
                            placeholder="选择银行打款日期"
                            :disabled="form.disabled"
                            value-format="yyyy-MM-dd">
                        </el-date-picker>
                    </el-form-item>
                  </el-col>
                  <el-col :span="8" v-if="form.title=='查看信息' && form.receiptSellBackTime!=null">
                    回执回销时间：{{form.receiptSellBackTime}}
                  </el-col>
                  <el-col :span="8" v-if="form.title=='查看信息'">
                    新老客户：{{form.customerType}}
                  </el-col>
                  <!-- <el-col :span="12">
                    <el-form-item label="备注:">
                      <el-input
                        clearable
                        placeholder="请输入备注"
                        v-model="form.remark">
                      </el-input>
                    </el-form-item>
                  </el-col> -->
                </el-row>   
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="sureAdd('form')"  :disabled="form.disabled">确 定</el-button>
                <el-button @click="cancelAdd">取 消</el-button>
              </div>
            </el-dialog>
          </template>
        </div>
        <!-- 回执回销时间 -->
        <el-dialog title="设置回执回销时间" :visible.sync="receiptSellBackTimeShow"
        :close-on-click-modal="false" width="30%">
          <span>回执回销时间：</span>
          <el-date-picker
            v-model="receiptSellBackTime"
            type="datetime"
            placeholder="选择日期时间"
            value-format="yyyy-MM-dd HH:mm:ss"
            default-time="12:00:00"
            :picker-options="birthdayOptions">
          </el-date-picker>
          <div slot="footer" class="dialog-footer">
              <el-button type="primary" @click="surereceiptSellBackTime" :loading="surereceiptSellBackTimeLoading">确 定</el-button>
              <el-button @click="cancelreceiptSellBackTime">取 消</el-button>
          </div>
        </el-dialog>
      </el-container>
    </div>
</template>
<script>
var productId = -1;
var salemanId = "";
var contractId = -1;
var searchInfo = {
  contractNo: "",
  salemanId: "",
  customerName: "",
  idcard: "",
  startInputTime: "",
  endInputTime: "",
  startReceiptSellBackTime: "",
  endReceiptSellBackTime: "",
  department:"",
};
export default {
  data() {
    return {
      exportLoading:false,
      contractNo: "",
      saleman: "",
      customerName: "",
      idcard: "",
      advanceSearchViewVisible: false,
      faangledoubleup: "fa-angle-double-up",
      faangledoubledown: "fa-angle-double-down",
      time1: [],
      time2: [],
      dialogFormVisible: false,
      inputContractNoLoading: false,
      inputsalemanNameLoading: false,
      dialogLoading: false,
      inputContractNoArray: [],
      inputsalemanNameArray: [],
      state4: "",
      department:"",
      departmentArr:"",
      birthdayOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        }
      },
      form: {
        title: "录入合同",
        contractNo: "",
        productName: "请输入合同编号",
        standardCoefficient: 0,
        customerName: "",
        idCard: "",
        sex: "男",
        birthday: "",
        age: "",
        payBankCard: "",
        receiveBankCard: "",
        payOpeningBank: "",
        receiveOpeningBank: "",
        telPhone: "",
        address: "",
        totalAssets: "",
        totalAssetsReturn: 0,
        investmentType: "",
        investmentTypeArray: [
          {
            value: "网银",
            label: "网银"
          },
          {
            value: "POS1",
            label: "POS1"
          },
          {
            value: "POS2",
            label: "POS2"
          },
          {
            value: "POS3",
            label: "POS3"
          },
          {
            value: "银行柜面",
            label: "银行柜面"
          },
          {
            value: "代付",
            label: "代付"
          }
        ],
        salemanName: "",
        // remark: "",
        countLoading: false,
        disabled: false,
        payDate:"",
        phoneDisable:false,
      },
      rules: {
        contractNo: [
          { required: true, message: "请输入合同编号", trigger: "blur" }
        ],
        customerName: [
          { required: true, message: "请输入资产受让人", trigger: "blur" }
        ],
        idCard: [
          { required: true, message: "请输入身份证号", trigger: "blur" }
        ],
        birthday: [{ required: true, message: "请输入生日", trigger: "blur" }],
        payDate:[{ required: true, message: "请输入打款日期", trigger: "blur" }],
        age: [{ required: true, message: "请输入年龄", trigger: "blur" }],
        payBankCard: [
          { required: true, message: "请输入打款账号", trigger: "blur" }
        ],
        receiveBankCard: [
          { required: true, message: "请输入收款账号", trigger: "blur" }
        ],
        payOpeningBank: [
          { required: true, message: "请输入打款银行开户行", trigger: "blur" }
        ],
        receiveOpeningBank: [
          { required: true, message: "请输入收款银行开户行", trigger: "blur" }
        ],
        telPhone: [
          { required: true, message: "请输入联系电话", trigger: "blur" }
        ],
        address: [
          { required: true, message: "请输入联系地址", trigger: "blur" }
        ],
        investmentType: [
          { required: true, message: "请选择投资方式", trigger: "change" }
        ],
        totalAssets: [
          { required: true, message: "请输入资产转让总额", trigger: "blur" }
        ],
        salemanName: [
          { required: true, message: "请输入服务人员", trigger: "blur" }
        ]
      },
      table: [],
      tableLoading: false,
      currentPage: 1,
      pageSize: 20,
      totalCount: 0,
      tableSearchModel: "common",
      receiptSellBackTimeShow: false,
      receiptSellBackTime: "",
      surereceiptSellBackTimeLoading: false
    };
  },
  mounted: function() {
    this.initData();
    this.getRequest("/auditor/getDepartmentList").then(resp=>{
      console.log(resp)
      if(resp &&resp.data.status==200){
        this.departmentArr=resp.data.obj
      }
    })
  },
  methods: {
    initData: function() {
      this.requestTableInfo(
        this.tableSearchModel,
        this.currentPage,
        this.pageSize
      );
    },
    // 请求列表数据
    requestTableInfo: function(model, pageCount, pageSize) {
      var that = this;
      //根据合同编号搜查的普通模式
      if (model == "common") {
        that.tableLoading = true;
        that
          .postRequest("/auditor/queryContract", {
            contractNo: that.contractNo,
            pageIndex: pageCount,
            pageSize: pageSize
          })
          .then(resp => {
            that.tableLoading = false;
            if (resp && resp.data.status == 200) {
              that.table = resp.data.obj.rows;
              that.totalCount = resp.data.obj.total;
              searchInfo = {
                contractNo: that.contractNo,
                salemanId: "",
                customerName: "",
                idcard: "",
                startInputTime: "",
                endInputTime: "",
                startReceiptSellBackTime: "",
                endReceiptSellBackTime: "",
                department:""
              };
            }
          });
      } else if (model == "senior") {
        //高级搜索模式
        this.time1 = this.time1 || [];
        this.time2 = this.time2 || [];
        this.time1[0] = this.time1[0] || "";
        this.time1[1] = this.time1[1] || "";
        this.time2[0] = this.time2[0] || "";
        this.time2[1] = this.time2[1] || "";
        that.tableLoading = true;
        that
          .postRequest("/auditor/queryContract", {
            salemanId: salemanId,
            customerName: this.customerName,
            idCard: this.idcard,
            startInputTime: this.time1[0],
            endInputTime: this.time1[1],
            startReceiptSellBackTime: this.time2[0],
            endReceiptSellBackTime: this.time2[1],
            department:this.department,
            pageIndex: pageCount,
            pageSize: pageSize
          })
          .then(resp => {
            that.tableLoading = false;
            if (resp && resp.data.status == 200) {
              that.table = resp.data.obj.rows;
              that.totalCount = resp.data.obj.total;
              searchInfo = {
                contractNo: "",
                salemanId: salemanId,
                customerName: that.customerName,
                idcard: that.idcard,
                startInputTime: this.time1[0],
                endInputTime: this.time1[1],
                startReceiptSellBackTime: this.time2[0],
                endReceiptSellBackTime: this.time2[1],
                department:this.department
              };
            }
          });
      }
    },
    //列表当前页改变
    currentChange: function(currentChange) {
      this.currentPage = currentChange;
      this.requestTableInfo(
        this.tableSearchModel,
        this.currentPage,
        this.pageSize
      );
    },
    //查看列表信息
    showEditEmpView: function(item) {
      item;
      this.dialogFormVisible = true;
      this.form = item;
      this.form.disabled = true;
      this.form.phoneDisable = true;
      this.form.title = "查看信息";
      this.form.totalAssetsReturn = item.returnRate;
      this.form.salemanName = item.salemanInfo.salemanName;
    },
    // 修改列表信息
    editEditEmpView: function(item) {
      // console.log(item);
      this.form = item;
      this.dialogFormVisible = true;
      productId = item.productId;
      salemanId = item.salemanId;
      contractId = item.contractId;
      this.form.disabled = false;
      this.form.phoneDisable = false;
      this.form.title = "修改信息";
      this.form.totalAssetsReturn = item.returnRate;
      this.form.salemanName = item.salemanInfo.salemanName;
      this.form.investmentTypeArray = [
        {
          value: "网银",
          label: "网银"
        },
        {
            value: "POS1",
            label: "POS1"
          },
          {
            value: "POS2",
            label: "POS2"
          },
          {
            value: "POS3",
            label: "POS3"
          },
        {
          value: "银行柜面",
          label: "银行柜面"
        },
        {
            value: "代付",
            label: "代付"
        }
      ];
    },
    //填写回执回销时间
    TimeEmp: function(item) {
      contractId = item.contractId;
      this.receiptSellBackTimeShow = true;
    },
    //确认回执回销时间
    surereceiptSellBackTime: function() {
      if (
        this.common.isNull(this.receiptSellBackTime) ||
        this.receiptSellBackTime == null
      ) {
        this.common.showToast("info", "请填写回执回销时间");
      } else {
        this.surereceiptSellBackTimeLoading = true;
        this.postRequest("/auditor/saveReceiptSellBackTime", {
          contractId: contractId,
          receiptSellBackTime: this.receiptSellBackTime
        }).then(resp => {
          this.surereceiptSellBackTimeLoading = false;
          if (resp && resp.data.status == 200) {
            this.common.showToast("success", resp.data.msg);
            this.receiptSellBackTimeShow = false;
            this.receiptSellBackTime = "";
            this.initData();
          }
        });
      }
    },
    cancelreceiptSellBackTime: function() {
      this.surereceiptSellBackTimeLoading = false;
      this.receiptSellBackTimeShow = false;
    },
    // 点击录入合同
    addContract: function() {
      this.dialogFormVisible = true;
      this.form.disabled = false;
      this.form.phoneDisable = false;
      this.form.title = "录入合同";
    },
    //身份证改变
    idCardChange: function(e) {
      if (e.length == 18) {
        if (e.substring(16, 17) % 2 == 1) {
          this.form.sex = "男";
        } else {
          this.form.sex = "女";
        }

        this.form.birthday =
          e.substring(6, 10) +
          "-" +
          e.substring(10, 12) +
          "-" +
          e.substring(12, 14);
          this.form.age=this.jsGetAge(this.form.birthday)
      } else {
        this.common.showToast("warning", "请输入正确的身份证号");
      }
    },
    //根据出生年月获取年龄
    jsGetAge(strBirthday) {
      var returnAge;
      // 根据生日计算年龄（"1995-09-25"）
      //以下五行是为了获取出生年月日，如果是从身份证上获取需要稍微改变一下
      var strBirthdayArr = strBirthday.split("-");
      var birthYear = strBirthdayArr[0];
      var birthMonth = strBirthdayArr[1];
      var birthDay = strBirthdayArr[2];

      var d = new Date();
      var nowYear = d.getFullYear();
      var nowMonth = d.getMonth() + 1;
      var nowDay = d.getDate();

      if (nowYear == birthYear) {
        returnAge = 0; //同年 则为0岁
      } else {
        var ageDiff = nowYear - birthYear; //年之差
        if (ageDiff > 0) {
          if (nowMonth == birthMonth) {
            var dayDiff = nowDay - birthDay; //日之差
            if (dayDiff < 0) {
              returnAge = ageDiff - 1;
            } else {
              returnAge = ageDiff;
            }
          } else {
            var monthDiff = nowMonth - birthMonth; //月之差
            if (monthDiff < 0) {
              returnAge = ageDiff - 1;
            } else {
              returnAge = ageDiff;
            }
          }
        } else {
          returnAge = -1; //返回-1 表示出生日期输入错误 晚于今天
        }
      }

      return returnAge; //返回周岁年龄
    },
    // 点击高级搜索
    showAdvanceSearchView() {
      this.advanceSearchViewVisible = !this.advanceSearchViewVisible;
      this.contractNo = "";
      if (this.tableSearchModel == "common") {
        this.tableSearchModel = "senior";
      } else if (this.tableSearchModel == "senior") {
        this.tableSearchModel = "common";
      }
    },
    //取消高级搜索
    cancelSearch: function() {
      this.advanceSearchViewVisible = false;
      this.tableSearchModel = "common";
    },
    // 普通搜索
    searchEmp: function() {
      this.currentPage = 1;
      this.requestTableInfo(
        this.tableSearchModel,
        this.currentPage,
        this.pageSize
      );
    },
    //高级搜索
    search: function() {
      this.currentPage = 1;
      this.requestTableInfo(
        this.tableSearchModel,
        this.currentPage,
        this.pageSize
      );
    },
    // 导出清单
    exportEmps: function() {      
      this.exportLoading = true; 
      var address=`/auditor/input_export_contract?contractNo=${searchInfo.contractNo}&&salemanId=${searchInfo.salemanId}&&startInputTime=${searchInfo.startInputTime}&&endInputTime=${searchInfo.endInputTime}&&startReceiptSellBackTime=${searchInfo.startReceiptSellBackTime}&&endReceiptSellBackTime=${searchInfo.endReceiptSellBackTime}&&customerName=${searchInfo.customerName}&&idCard=${searchInfo.idcard}&&department=${searchInfo.department}`;
      this.common.downloadFile(address); 
      setTimeout(() => {
        this.exportLoading =false;
      }, 2000);
      // this.$nextTick(function(){
      //   this.exportLoading = false; 
      // })
    },
    //输入合同编号
    inputContractNoMethod: function(query) {
      if (query !== "") {
        this.inputContractNoLoading = true;
        this.getRequest("/auditor/matchingContractNo?contractNo=" + query).then(
          resp => {
            if (resp && resp.data.status == 200) {
              this.inputContractNoArray = resp.data.obj;
            }
            this.inputContractNoLoading = false;
          }
        );
      } else {
        this.inputContractNoArray = [];
      }
    },
    // 合同编号发生变化
    contractNoChange: function(e) {
      var that = this;
      if (e == "") {
        this.form.productName = "请输入合同编号";
        this.form.standardCoefficient = 0;
        productId = -1;
      } else {
        this.getRequest("/auditor/matchingContractNo?contractNo=" + e)
          .then(resp => {
            if (resp && resp.data.status == 200) {
              productId = resp.data.obj[0].productId;
              return resp.data.obj[0].productId;
            }
          })
          .then(function(data) {
            that.getRequest("/common/get?productId=" + data).then(resp => {
              if (resp && resp.data.status == 200) {
                that.form.productName = resp.data.obj.productName;
                that.form.standardCoefficient =
                  resp.data.obj.standardCoefficient;
              }
            });
          });
      }
      this.form.contractNo = e;
    },
    //输入资产受让人
    querySearchAsync(queryString, cb) {
      var that = this;
      if (queryString != "") {
        that
          .getRequest("/auditor/matchingCustomer?customerName=" + queryString)
          .then(resp => {
            if (resp && resp.data.status == 200) {
              var results = [];
              var string = resp.data.obj;
              results = queryString
                ? string.filter(this.createStateFilter(queryString))
                : string;
              cb(results);
            }
          });
      } else {
        this.form.phoneDisable = false;
        //当资产受让人被清空的时候，将原来带上的信息清空
        // this.form.idCard = "";
        // this.form.sex = "";
        // this.form.birthday = "";
        // this.form.age = "";
        // this.form.payBankCard = "";
        // this.form.receiveBankCard = "";
        // this.form.payOpeningBank = "";
        // this.form.receiveOpeningBank = "";
        // this.form.telPhone = "";
        // this.form.address = "";
        cb(queryString ? [].filter(this.createStateFilter(queryString)) : []);
      }
    },
    // 搜索匹配资产受让人的过滤器
    createStateFilter(queryString) {
      return state => {
        state.value = state.customerName; //匹配显示的字段必须叫value
        state.idCard = state.idCard;
        return (
          state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
        );
      };
    },
    //选择资产受让人
    selectName: function(item) {
      console.log(item)
      this.form.idCard = item.idCard;
      this.form.sex = item.sex;
      this.form.birthday = item.birthday;
      this.form.age = item.age;
      this.form.payBankCard = item.payBankCard;
      this.form.receiveBankCard = item.receiveBankCard;
      this.form.payOpeningBank = item.payOpeningBank;
      this.form.receiveOpeningBank = item.receiveOpeningBank;
      this.form.telPhone = item.telPhone;
      this.form.address = item.address;
      this.form.phoneDisable=true;
    },
    //计算收益率
    countProfit: function() {
      var that = this;
      if (productId == -1) {
        this.common.showToast("info", "请输入合同编号");
      } else if (this.common.isNull(this.form.totalAssets)) {
        this.common.showToast("info", "请输入资产转让总额");
      } else {
        that.dialogLoading = true;
        that.form.countLoading = true;
        that
          .getRequest(
            "/auditor/investmentFormulaCalc?productId=" +
              productId +
              "&totalAssets=" +
              that.form.totalAssets
          )
          .then(resp => {
            that.dialogLoading = false;
            that.form.countLoading = false;
            if (resp && resp.data.status == 200) {
              that.form.totalAssetsReturn = resp.data.obj;
            }
          });
      }
    },
    // 输入服务人员
    inputsalemanNameMethod: function(query) {
      if (query !== "") {
        this.inputsalemanNameLoading = true;
        this.getRequest("/auditor/matchingSaleman?salemanName=" + query).then(
          resp => {
            if (resp && resp.data.status == 200) {
              this.inputsalemanNameArray = resp.data.obj;
            }
            this.inputsalemanNameLoading = false;
          }
        );
      } else {
        this.inputsalemanNameArray = [];
      }
    },
    // 服务人员发生变化
    salemanNameChange: function(e) {
      var that = this;
      if (e == "") {
        salemanId = "";
      } else {
        that.dialogLoading = true;
        this.getRequest("/auditor/matchingSaleman?salemanName=" + e).then(
          resp => {
            that.dialogLoading = false;
            if (resp && resp.data.status == 200) {
              salemanId = resp.data.obj[0].salemanId;
            }
          }
        );
      }
    },
    //确认录入
    sureAdd: function(form) {
      console.log(this.form);
      this.$refs[form].validate(valid => {
        if (valid) {
          this.dialogLoading = true;
          var that = this;
          if (this.form.title == "录入合同") {
            this.putRequest("/auditor/insert", {
              contractNo: this.form.contractNo,
              productName: this.form.productName,
              productId: productId,
              totalAssets: this.form.totalAssets,
              investmentType: this.form.investmentType,
              salemanId: salemanId,
              customerName: this.form.customerName,
              idCard: this.form.idCard,
              sex: this.form.sex,
              birthday: this.form.birthday,
              payBankCard: this.form.payBankCard,
              payOpeningBank: this.form.payOpeningBank,
              receiveBankCard: this.form.receiveBankCard,
              receiveOpeningBank: this.form.receiveOpeningBank,
              telPhone: this.form.telPhone,
              address: this.form.address,
              payDate:this.form.payDate,
              // remark: this.form.remark
            }).then(resp => {
              that.dialogLoading = false;
              if (resp && resp.data.status == 200) {
                that.dialogFormVisible = false;
                that.common.showToast("success", resp.data.msg);
                this.formInit();
                this.initData();
              }
            });
          } else if (this.form.title == "修改信息") {
            this.putRequest("/auditor/update", {
              contractId: contractId,
              contractNo: this.form.contractNo,
              productName: this.form.productName,
              productId: productId,
              totalAssets: this.form.totalAssets,
              investmentType: this.form.investmentType,
              salemanId: salemanId,
              customerName: this.form.customerName,
              idCard: this.form.idCard,
              sex: this.form.sex,
              birthday: this.form.birthday,
              payBankCard: this.form.payBankCard,
              payOpeningBank: this.form.payOpeningBank,
              receiveBankCard: this.form.receiveBankCard,
              receiveOpeningBank: this.form.receiveOpeningBank,
              telPhone: this.form.telPhone,
              address: this.form.address,
              payDate:this.form.payDate,
              // remark: this.form.remark
            }).then(resp => {
              that.dialogLoading = false;
              if (resp && resp.data.status == 200) {
                that.dialogFormVisible = false;
                that.common.showToast("success", resp.data.msg);
                this.formInit();
                this.initData();
              }
            });
          }
        } else {
          return false;
        }
      });
    },
    cancelAdd: function() {
      this.dialogFormVisible = false;
    },
    dialogClose: function() {
      //如果不是录入合同状态关闭的，则清空form表单内容
      if (this.form.title != "录入合同") {
        this.formInit();
        this.initData();
      }
    },
    // 表单初始化
    formInit: function() {
      salemanId = "";
      productId = -1;
      this.form = {
        title: "录入合同",
        contractNo: "",
        productName: "请输入合同编号",
        standardCoefficient: 0,
        customerName: "",
        idCard: "",
        sex: "男",
        birthday: "",
        age: "",
        payBankCard: "",
        receiveBankCard: "",
        payOpeningBank: "",
        receiveOpeningBank: "",
        telPhone: "",
        address: "",
        totalAssets: "",
        totalAssetsReturn: 0,
        investmentType: "",
        investmentTypeArray: [
          {
            value: "网银",
            label: "网银"
          },
          {
            value: "POS1",
            label: "POS1"
          },
          {
            value: "POS2",
            label: "POS2"
          },
          {
            value: "POS3",
            label: "POS3"
          },
          {
            value: "银行柜面",
            label: "银行柜面"
          },
          {
            value: "代付",
            label: "代付"
          }
        ],
        salemanName: "",
        // remark: "",
        countLoading: false,
        disabled: false
      };
    }
  }
};
</script>
<style scoped>
.el-row {
  margin-top: 10px;
}
.el-col {
  height: 50px;
  line-height: 50px;
  text-align: left;
}
.el-input {
  width: 70%;
}
.el-dialog__body {
  padding-top: 0px;
  padding-bottom: 0px;
}

.slide-fade-enter-active {
  transition: all 0.8s ease;
}

.slide-fade-leave-active {
  transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
}

.slide-fade-enter,
.slide-fade-leave-to {
  transform: translateX(10px);
  opacity: 0;
}
.idcard {
  border-bottom: 1px solid #ccc;
}
.senior {
  margin-bottom: 10px;
  border: 1px;
  border-radius: 5px;
  border-style: solid;
  padding: 10px;
  box-sizing: border-box;
  border-color: #20a0ff;
}
.senior .el-input {
  width: 200px;
}
.senior .el-date-editor {
  width: 250px;
}
#inputContract .el-input {
  width: 50%;
}
#inputContract .el-date-editor {
  width: 50%;
}
#inputContract .longinput .el-input {
  width: 60%;
}
</style>
